/**
 * 
 */
package lexicon;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Jamada
 */
public class BuildLexiconHashMap {
    
    //private static final String LEXICON_FILE = "C:/Users/Jamada/Desktop/fb_status_updates/NRC_Lexicon.csv";
    
    private static final int NUM_LEXICON_SENTIMENTS = 10;
    
    public static void lexiconHashMap(final String fileName) throws IOException {
        final BufferedReader bReader = new BufferedReader(new FileReader(fileName));
        final Map<String, int[]> lexiconMap = new HashMap<String, int[]>();
        String line;
        bReader.readLine();
        int count = 0;
        while ((line = bReader.readLine()) != null) {
            final int[] sentimentScores = new int[NUM_LEXICON_SENTIMENTS];
            String values[] = line.split(",");
            for (int i = 1; i < values.length; i++) {
                sentimentScores[i - 1] = Integer.parseInt(values[i]);
            }
            lexiconMap.put(values[0], sentimentScores);
            count++;
        }
        bReader.close();
        
        //Serialize Hash Map
        try {
            FileOutputStream fileOutStream = new FileOutputStream("LexiconHashMap.ser");
            ObjectOutputStream ObjectOutStream = new ObjectOutputStream(fileOutStream);
            ObjectOutStream.writeObject(lexiconMap);
            ObjectOutStream.close();
            fileOutStream.close();
            System.out.println(count + " entries in Hash Map");
            System.out.printf("Serialized Hash Map data is saved in LexiconHashMap.ser");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
//  /**
//  * @param args
//  */
// public static void main(String[] args) {      
//     try {
//         lexiconHashMap(LEXICON_FILE);
//     } catch (IOException e) {
//         e.printStackTrace();
//     }
// }
}
